package com.ruoyi.pay.service;

import com.alipay.api.AlipayApiException;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.pay.clients.OrderFeignCliest;
import com.ruoyi.pay.entity.TbOrder;
import com.ruoyi.pay.utils.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

@Service
public class AggregationPayService {
    @Autowired
    AliPayService aliPayService;
    @Autowired
    WXPayService wxPayService;
    @Autowired
    OrderFeignCliest orderFeignCliest;

    /**
     * 统一支付接口
     * @param orderId
     * @param payType
     * @return
     */
    public String aggregationPay(Integer orderId, Integer payType) throws Exception {
        //通过订单id 查询
        TbOrder tbOrder = orderFeignCliest.finOrderByid(Long.valueOf(orderId));
        //支付类型1 支付宝  支付类型二 微信支付 //支付类型 3  扫脸支付
        if(payType == 1){
            IdWorker idWorker = new IdWorker();
            long aliIdword = idWorker.nextId();
            String pagePay = aliPayService.alipay_trade_page_pay(String.valueOf(aliIdword), Double.valueOf(tbOrder.getTotalAmount()), tbOrder.getCuserName(), "支付账单");
            System.out.println(pagePay);
            return pagePay;
        }
        if(payType == 2){
            IdWorker idWorker = new IdWorker();
            long orderIdIdwork = idWorker.nextId();
            String wxPay = wxPayService.unifiedOrder(orderIdIdwork, Integer.valueOf(tbOrder.getTotalAmount()), tbOrder.getCuserName());
            return  wxPay;
        }
        if(payType == 3){
            System.out.println("触发人脸识别");
            String mag = "扫脸支付完成";
            return  mag;
        }
        return null;

    }
}
